import Vue from 'vue'
import Router from 'vue-router'
import login from '@/view/login/login'
import sideBar from '@/components/sideBar/sideBar'
import personalCenter from '@/view/personalCenter/personalCenter'
import personInfo from '@/view/personInfo/personInfo'
import sellerManager from '@/view/sellerManager/sellerManager'
import orderManager from '@/view/orderManager/orderManager'
import productsManager from '@/view/productsManager/productsManager'
import pieChart from '@/view/charts/pieChart'

Vue.use(Router)
const router = new Router({
  mode: 'history',
  routes: [{
      path: '/personalCenter',
      name: 'personalCenter',
      redirect: '/personalCenter/personInfo',
      component: personalCenter,
      children: [
        {
          path: 'pieChart',
          name: 'pieChart',
          component: pieChart,
          meta: {
            title: '销量数据'
          }
        },
        {
          path: 'productsManager',
          name: 'productsManager',
          component: productsManager,
          meta: {
            title: '商品管理'
          }
        },
        {
          path: 'orderManager',
          name: 'orderManager',
          component: orderManager,
          meta: {
            title: '订单管理'
          }
        }
        ,{
        path: 'personInfo',
        name: 'personInfo',
        component: personInfo,
        meta: {
          title: '店铺概览'
        }
      }, {
        path: 'sellerManager',
        name: 'sellerManager',
        component: sellerManager,
        meta: {
          title: '店铺管理'
        }
      }],
      meta: {
        title: '首页'
      }
    }, {
      path: '/sideBar',
      name: 'sideBar',
      component: sideBar,
      meta: {
        title: '资料'
      }
    }
    , {
      path: '/',
      name: 'index',
      // component: login,
      redirect: '/login',
      meta: {
        title: '入口'
      }
    }
    , {
      path: '/login',
      name: 'login',
      component: login,
      meta: {
        title: '登录'
      }
    }
  ]
})
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面meta */
  if (to.meta.content) {
    let head = document.getElementsByTagName('head');
    let meta = document.createElement('meta');
    meta.content = to.meta.content;
    head[0].appendChild(meta)
  }
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next()
});
export default router
